home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
bbsutil
/
bsrc_250.zip
/
GET_LANG.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-09-15
|
16KB
|
408 lines
/*--------------------------------------------------------------------------*/
/* */
/* */
/* ------------ Bit-Bucket Software, Co. */
/* \ 10001101 / Writers and Distributors of */
/* \ 011110 / Freely Available<tm> Software. */
/* \ 1011 / */
/* ------ */
/* */
/* (C) Copyright 1987-91, Bit Bucket Software Co., a Delaware Corporation. */
/* */
/* */
/* This module was written by Vince Perriello */
/* */
/* */
/* BinkleyTerm Language Compiler Raw Input Module */
/* */
/* */
/* For complete details of the licensing restrictions, please refer */
/* to the License agreement, which is published in its entirety in */
/* the MAKEFILE and BT.C, and also contained in the file LICENSE.250. */
/* */
/* USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE */
/* BINKLEYTERM LICENSING AGREEMENT. IF YOU DO NOT FIND THE TEXT OF */
/* THIS AGREEMENT IN ANY OF THE AFOREMENTIONED FILES, OR IF YOU DO */
/* NOT HAVE THESE FILES, YOU SHOULD IMMEDIATELY CONTACT BIT BUCKET */
/* SOFTWARE CO. AT ONE OF THE ADDRESSES LISTED BELOW. IN NO EVENT */
/* SHOULD YOU PROCEED TO USE THIS FILE WITHOUT HAVING ACCEPTED THE */
/* TERMS OF THE BINKLEYTERM LICENSING AGREEMENT, OR SUCH OTHER */
/* AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO. */
/* */
/* */
/* You can contact Bit Bucket Software Co. at any one of the following */
/* addresses: */
/* */
/* Bit Bucket Software Co. FidoNet 1:104/501, 1:343/491 */
/* P.O. Box 460398 AlterNet 7:491/0 */
/* Aurora, CO 80046 BBS-Net 86:2030/1 */
/* Internet f491.n343.z1.fidonet.org */
/* */
/* Please feel free to contact us at any time to share your comments about */
/* our software and/or licensing policies. */
/* */
/*--------------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef __TURBOC__
#include <mem.h>
#else
#ifdef _MSC_VER_
#include <memory.h>
#else
#include <string.h>
#endif
#endif
#ifdef OS_2
#define OS_IDENT "OS2"
#else
#define OS_IDENT "DOS"
#endif
#include "language.h"
int parse_escapes (char *);
/*
* get_language - read in BinkleyTerm language source
*
* Read lines into table, ignoring blanks and comments
* Store into a contiguous block of memory with the individual
* members being referenced by an array of pointers
* Store number of lines read into pointer_size
* Store amount of memory used into memory_size
*
*/
int get_language (char *name_of_file)
{
int len; /* length of current string */
int count_from_file; /* no. of strings in file */
int file_version; /* version of file */
char *p, *q; /* miscellaneous pointers */
char *storage; /* where we're storing now */
char **load_pointers; /* pointer to pointer array */
char linebuf[255]; /* biggest line we'll allow */
FILE *fpt; /* stream pointer */
int internal_count; /* How many strings we got */
int total_size; /* How big it all is */
int error; /* Internal error value */
int PrdctCode; /* Product Code */
char *PrdctNm;
char *PrdctPtr = PrdctMem;
char *n;
char *LangStart;
unsigned int ansival; /* Scanned ANSI keymap value */
internal_count = 0; /* zero out internal counter */
count_from_file = 0; /* zero out internal counter */
total_size = 0; /* Initialize storage size */
error = 0; /* Initialize error value */
load_pointers = pointers; /* Start at the beginning */
storage = memory; /* A very good place to start*/
/*
* Open the file now. Then read in the appropriate table. First line of
* the file contains the number of lines we want Second line through end:
* ignore if it starts with a ; and store only up to ;
*
*/
fpt = fopen (name_of_file, "r"); /* Open the file */
if (fpt == NULL) /* Were we successful? */
{
(void) fprintf (stderr, "Can not open input file %s\n", name_of_file);
return (-1); /* Return failure to caller */
}
while (fgets (linebuf, 254, fpt) != NULL) /* read a line in */
{
p = q = linebuf; /* set up for scan */
/*
* This label is only hit when a ? line is seen.
*
* The format of a ? line is:
*
* ?xxx ....
*
* where xxx is a 3-character platform identifier. For DOS systems,
* the identifier is DOS and for OS/2 it is OS2. The text following
* ?xxx is the same format as any other language file line.
*
* When we see a ?, we compare the following string to the ID of our
* current platform. If it matches, we point p and q at the text following
* the expression, and (I'm sorry) jump back. If it doesn't match, we throw
* the line away.
*/
re_cycle:
switch (*p)
{
case '?':
if (strncmp (++p, OS_IDENT, 3) == 0)
{
q = p += 3;
goto re_cycle;
}
break;
case ';': /* Comment */
case 'C': /* Comment */
break;
case 'L': /* Language Line */
LangStart = ++p;
(void) parse_escapes (p);
if ((len = strlen (p)) == 0) /* Is anything there? */
continue; /* No -- ignore. */
if (!count_from_file)
{
(void) sscanf (LangStart,"%d %d",&count_from_file, &file_version);
if (count_from_file <= pointer_size)